package com.lagou.consumer.web;

import com.lagou.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;

/**
 * <h1>用户服务控制层</h1>
 * @author yzh
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Reference
    private UserService userService;

    @RequestMapping("/sayHello")
    @ResponseBody
    public String sayHello(String name, HttpServletRequest request) {
        RpcContext.getContext().setAttachment("CLIENT_IP", request.getRemoteAddr());
        String result = userService.sayHello("yzh");
        System.out.println("---------------UserService call result:"+result+"---------------");
        return "<h1>"+result+"</h1>";
    }
}
